const state = {
  availableLevels: ['B1', 'F1', 'F2', 'F3'],
  poisList: [],
  currentRoute: null
}

const mutations = {
  SET_AVAILABLE_LEVELS(state, levels) {
    state.availableLevels = levels
  },
  SET_POIS_LIST(state, pois) {
    state.poisList = pois
  },
  SET_CURRENT_ROUTE(state, route) {
    state.currentRoute = route
  }
}

const actions = {
  // 加载POI列表
  async loadPoisList({ commit }) {
    try {
      // 模拟API调用
      const mockPois = [
        { id: '1', name: '门诊大厅', level: 'F1', type: 'service' },
        { id: '2', name: '急诊科', level: 'F1', type: 'department' },
        { id: '3', name: '内科', level: 'F2', type: 'department' },
        { id: '4', name: '外科', level: 'F3', type: 'department' }
      ]
      
      commit('SET_POIS_LIST', mockPois)
    } catch (error) {
      console.error('加载POI列表失败:', error)
    }
  },

  // 搜索POI
  async searchPois({ commit }, keyword) {
    try {
      // 模拟API调用
      const results = [
        { id: '1', name: '内科门诊', level: 'F2', type: 'department' }
      ]
      return results
    } catch (error) {
      console.error('搜索POI失败:', error)
      return []
    }
  },

  // 路线规划API
  async planRouteApi({ commit }, { from, to }) {
    try {
      // 模拟路线规划
      const mockRoute = {
        distance: 150,
        duration: 300,
        steps: [
          { instruction: '从大厅出发', distance: 50 },
          { instruction: '左转进入电梯间', distance: 30 },
          { instruction: '乘坐电梯至F2', distance: 0 },
          { instruction: '右转直行70米到达内科', distance: 70 }
        ]
      }
      
      commit('SET_CURRENT_ROUTE', mockRoute)
      return mockRoute
    } catch (error) {
      console.error('路线规划失败:', error)
      throw error
    }
  },

  // 加载地图数据
  async loadMapData({ commit }) {
    try {
      // 模拟加载地图数据
      console.log('地图数据加载完成')
    } catch (error) {
      console.error('加载地图数据失败:', error)
    }
  }
}

const getters = {
  availableLevels: state => state.availableLevels,
  poisList: state => state.poisList,
  currentRoute: state => state.currentRoute
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}